import math, time
from concurrent.futures import ThreadPoolExecutor, ProcessPoolExecutor

PRIME = [112272535095293] * 70

def is_prime(n):
    if n < 2:
        return False
    if n == 2:
        return True
    if n % 2 == 0:
        return False
    sqrt_n = int(math.floor(math.sqrt(n)))
    for i in range(3, sqrt_n + 1, 2):
        if n % i == 0:
            return False
    return True

def single_thread():
    for n in PRIME:
        is_prime(n)

def multi_thread():
    with ThreadPoolExecutor() as pool:
        pool.map(is_prime, PRIME)

def multi_process():
    with ProcessPoolExecutor() as pool:
        pool.map(is_prime, PRIME)

if __name__ == '__main__':
    start = time.time()
    single_thread()
    end = time.time()
    print('Single thread: ', end - start)

    start = time.time()
    multi_thread()
    end = time.time()
    print('Multi thread: ', end - start)

    # 数据比较多时，多进程速度快，占优势
    start = time.time()
    multi_process()
    end = time.time()
    print('Multi process: ', end - start)